package com.eascs.p2p.wallet.dubbo;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.common.entity.InvestorEntity;
import com.eascs.p2p.common.entity.InvestorWalletEntity;
import com.eascs.p2p.common.entity.InvestorWalletFlowEntity;
import com.eascs.p2p.common.entity.InvestorWalletPayEntity;
import com.eascs.p2p.common.entity.InvestorWithdrawRecordEntity;
import com.eascs.p2p.common.vo.InvestorWithdrawRecordVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.common.vo.RepaymentVO;
import com.eascs.p2p.common.wallet.service.InvestorWalletService;
import com.eascs.p2p.wallet.server.InvestorWalletServiceInner;

@Service
public class InvestorWalletDubboServiceImpl implements InvestorWalletService {
	private static Logger logger = LoggerFactory.getLogger(InvestorWalletDubboServiceImpl.class);

	@Autowired
	private InvestorWalletServiceInner investorWalletService;

	@Override
	public ModelResult<InvestorWalletEntity> queryInvestorWallet(String investorId) {
		return investorWalletService.queryInvestorWallet(investorId);
	}

	@Override
	public ModelResult<PageResult<InvestorWalletFlowEntity>> queryInvestorWalletFlowByPage(String investorId,
			int transType, int pageSize, int pageIndex) {
		return investorWalletService.queryInvestorWalletFlowByPage(investorId, transType, pageSize, pageIndex);
	}

	@Override
	public ModelResult<Boolean> stopInvestWalletFlow(String investObjId) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.stopInvestWalletFlow(investObjId);
		} catch (Exception e) {
			logger.error("标的终止钱包流水处理失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.stopInvestWalletFlow", "标的终止钱包流水处理失败");
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> insertInvestorWalletPay(InvestorWalletPayEntity investorWalletPay) {
		return investorWalletService.insertInvestorWalletPay(investorWalletPay);
	}

	@Override
	public ModelResult<Boolean> updateInvestorWalletPay(InvestorWalletPayEntity investorWalletPay) {
		return investorWalletService.updateInvestorWalletPay(investorWalletPay);
	}

	@Override
	public ModelResult<Boolean> investorWalletPay(String requestno) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.investorWalletPay(requestno);
		} catch (Exception e) {
			logger.error("充值失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.investorWalletPay", "充值失败");
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> investorWalletWithdraw(InvestorEntity investor, BigDecimal drawMoney) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.investorWalletWithdraw(investor, drawMoney);
		} catch (Exception e) {
			logger.error("提款失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.investorWalletWithdraw", "提款失败");
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> investorWalletWithdrawConfirm(String requestno) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.investorWalletWithdrawConfirm(requestno);
		} catch (Exception e) {
			logger.error("提款确认失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.investorWalletWithdrawConfirm", "提款确认失败");
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> insertWithdrawRecord(InvestorWithdrawRecordEntity withdrawRecord) {
		return investorWalletService.insertWithdrawRecord(withdrawRecord);
	}

	@Override
	public ModelResult<Boolean> updateWithdrawRecord(InvestorWithdrawRecordEntity withdrawRecord) {
		return investorWalletService.updateWithdrawRecord(withdrawRecord);
	}

	@Override
	public ModelResult<InvestorWithdrawRecordEntity> queryWithdrawRecordById(String id) {
		return investorWalletService.queryWithdrawRecordById(id);
	}

	@Override
	public ModelResult<PageResult<Object[]>> findPageInvestorWithdrawRecord(InvestorWithdrawRecordVO vo) {
		
		return investorWalletService.findPageInvestorWithdrawRecord(vo);
	}

	@Override
	public ModelResult<Boolean> repaymentWalletHandle(List<RepaymentVO> repayments) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.repaymentWalletHandle(repayments);
		} catch (Exception e) {
			logger.error("还款钱包流水插入失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.repaymentWalletHandle", "还款钱包流水插入失败");
			e.printStackTrace();
		}
		return result;
	}

	/*@Override
	public ModelResult<Boolean> makeLoansInvestWalletFlow(String investObjId) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorWalletService.makeLoansInvestWalletFlow(investObjId);
		} catch (Exception e) {
			logger.error("标的放款钱包流水处理失败, error:{}", e.getMessage());
			result.withError("InvestorWalletServiceInnerImpl.makeLoansInvestWalletFlow", "标的放款钱包流水处理失败");
			e.printStackTrace();
		}
		return result;
	}*/

}
